#include"process.h"
#include<time.h>
#include<stdlib.h>

//函数指针类型
typedef void (*call_t)(double, double);

double total = 1024.0; //下载的总量;
double speed[] = {1.0, 0.5, 0.3, 0.2, 0.01, 0.001}; // 下载速度-网速

void download(int total, call_t cb)
{
    srand(time(NULL));
    double current = 0.0;

    while (current <= total)
    {
        cb(total, current);// 进行回调

        if (current >= total) break;

        //下面的代码是模拟资源的下载
        usleep(500);
        current += speed[rand() % sizeof(speed)];

        if (current >= total) current = total;
    }
}
int main()
{
    download(1024.0, FlushProcess);
    printf("download 1024.0MB done\n");

    download(512.0, FlushProcess);
    printf("download 512.0MB done\n");

    download(256.0, FlushProcess);
    printf("download 256.0MB done\n");

    download(128.0, FlushProcess);
    printf("download 128.0MB done\n");

    return 0;
}




